#include "regutil.h"
#include <QSettings>

QString RegUtil::readConfigValue(const QString &path, const QString &key)
{
    QSettings setting(path, QSettings::NativeFormat);
    return setting.value(key).toString();
}

QVariantMap RegUtil::readConfigValues(const QString &path)
{
    QVariantMap values;
    QSettings setting(path, QSettings::NativeFormat);
    QStringList groupList = setting.childGroups();
    for (const QString &group : groupList)
    {
        QVariantMap vl;
        setting.beginGroup(group);
        foreach (QString key, setting.childKeys())
            vl.insert(key, setting.value(key));
        setting.endGroup();
        values.unite(vl);
    }
    return values;
}

bool RegUtil::writeConfigValue(const QString &path, const QString &key, const QVariant &value)
{
    QSettings setting(path, QSettings::NativeFormat);
    setting.setValue(key, value);
    return true;
}

bool RegUtil::writeConfigValues(const QString &path, const QVariantMap &values)
{
    QSettings setting(path, QSettings::NativeFormat);
    QVariantMap::const_iterator it;
    for (it = values.cbegin(); it != values.cend(); ++it)
    {
        setting.setValue(it.key(), it.value());
    }
    return true;
}
